package vn.hust.homebudget.core.dao.database;

import android.database.sqlite.SQLiteDatabase;

public class ProcessSchema {
	public static final String TABLE_INCOMES = "incomes";
	
	public static final String COLUMN_INCOMES_ID = "incomes_id";
	public static final String COLUMN_INCOMES_ID_CATEGORY = "incomes_category";
	public static final String COLUMN_INCOMES_ID_PAYER = "incomes_payer";
	public static final String COLUMN_INCOMES_ID_ACCOUNT = "incomes_account";
	public static final String COLUMN_INCOMES_PICTURE = "incomes_picture";
	public static final String COLUMN_INCOMES_SOUND_REC = "incomes_sound_rec";
	public static final String COLUMN_INCOMES_AMOUNT = "incomes_amount";
	public static final String COLUMN_INCOMES_TIME = "incomes_time";
	public static final String COLUMN_INCOMES_PLACE = "incomes_place";
	public static final String COLUMN_INCOMES_PHONE = "incomes_phone";
	public static final String COLUMN_INCOMES_CONTENT = "incomes_content";
	
	public static final String TABLE_EXPENSES = "expenses";
	
	public static final String COLUMN_EXPENSES_ID = "expenses_id";
	public static final String COLUMN_EXPENSES_ID_CATEGORY = "expenses_category";
	public static final String COLUMN_EXPENSES_ID_PAYEE = "expenses_payee";
	public static final String COLUMN_EXPENSES_ID_ACCOUNT = "expenses_account";
	public static final String COLUMN_EXPENSES_ID_PICTURE = "expenses_picture";
	public static final String COLUMN_EXPENSES_ID_SOUND_REC = "expenses_sound_rec";
	public static final String COLUMN_EXPENSES_AMOUNT = "expenses_amount";
	public static final String COLUMN_EXPENSES_TIME = "expenses_time";
	public static final String COLUMN_EXPENSES_PLACE = "expenses_place";
	public static final String COLUMN_EXPENSES_PHONE = "expenses_phone";
	public static final String COLUMN_EXPENSES_CONTENT = "expenses_content";
	
	public static final String TABLE_PAYEE = "payee";

	public static final String COLUMN_PAYEE_ID = "id_payee";
	public static final String COLUMN_PAYEE_NAME = "payee_name";
	public static final String COLUMN_PAYEE_CONTACT = "payee_contact";
	
	public static final String TABLE_PAYER = "payer";

	public static final String COLUMN_PAYER_ID = "id_payer";
	public static final String COLUMN_PAYER_NAME = "payer_name";
	public static final String COLUMN_PAYER_CONTACT = "payer_contact";
	
	public static final String TABLE_ACCOUNT = "account";
	
	public static final String COLUMN_ACCOUNT_ID = "id_account";
	public static final String COLUMN_ACCOUNT_NAME = "account_name";
	
	public static final String TABLE_CATEGORY = "category";
	
	public static final String COLUMN_CATEGORY_ID = "id_category";
	public static final String COLUMN_CATEGORY_NAME = "category_name";
	public static final String COLUMN_CATEGORY_AVAR = "category_avar";
	
	private static final String COMMAND_CREATE_INCOMES = "CREATE TABLE " + 
			TABLE_INCOMES + "(" + COLUMN_INCOMES_ID + " INTEGER PRIMARY KEY  AUTOINCREMENT NOT NULL," + 
			COLUMN_INCOMES_ID_CATEGORY + " INTEGER," + COLUMN_INCOMES_ID_PAYER + " INTEGER," + 
			COLUMN_INCOMES_ID_ACCOUNT + " INTEGER," + COLUMN_INCOMES_PICTURE + " VARCHAR," + 
			COLUMN_INCOMES_SOUND_REC + " VARCHAR," + COLUMN_INCOMES_AMOUNT + " LONG," + 
			COLUMN_INCOMES_TIME + " LONG," + COLUMN_INCOMES_PLACE + " VARCHAR," + 
			COLUMN_INCOMES_PHONE + " VARCHAR," + COLUMN_INCOMES_CONTENT + " VARCHAR )";
	
	private static final String COMMAND_CREATE_EXPENSES = "CREATE TABLE " + 
			TABLE_EXPENSES + "(" + COLUMN_EXPENSES_ID + " INTEGER PRIMARY KEY  AUTOINCREMENT NOT NULL," + 
			COLUMN_EXPENSES_ID_CATEGORY + " INTEGER," + COLUMN_EXPENSES_ID_PAYEE + " INTEGER," + 
			COLUMN_EXPENSES_ID_ACCOUNT + " INTEGER," + COLUMN_EXPENSES_ID_PICTURE + " INTEGER," + 
			COLUMN_EXPENSES_ID_SOUND_REC + " INTEGER," + COLUMN_EXPENSES_AMOUNT + " LONG," + 
			COLUMN_EXPENSES_TIME + " LONG," + COLUMN_EXPENSES_PLACE + " VARCHAR," + 
			COLUMN_EXPENSES_PHONE + " VARCHAR," + COLUMN_EXPENSES_CONTENT + " VARCHAR )";
    
	private static final String COMMAND_CREATE_PAYEE = "CREATE TABLE " + 
			TABLE_PAYEE + "(" + COLUMN_PAYEE_ID + " INTEGER PRIMARY KEY  AUTOINCREMENT NOT NULL,"  + 
			COLUMN_PAYEE_NAME + " VARCHAR," + COLUMN_PAYEE_CONTACT +  "VARCHAR )";
	
	private static final String COMMAND_CREATE_PAYER = "CREATE TABLE " + 
			TABLE_PAYER + "(" + COLUMN_PAYER_ID + " INTEGER PRIMARY KEY  AUTOINCREMENT NOT NULL,"  + 
			COLUMN_PAYER_NAME + " VARCHAR," + COLUMN_PAYER_CONTACT +  "VARCHAR )";
	
	private static final String COMMAND_CREATE_ACCOUNT = "CREATE TABLE " + 
			TABLE_ACCOUNT + "(" + COLUMN_ACCOUNT_ID + " INTEGER PRIMARY KEY  AUTOINCREMENT NOT NULL,"  + 
			COLUMN_ACCOUNT_NAME +  "VARCHAR )";
	
	private static final String COMMAND_CREATE_CATEGORY = "CREATE TABLE " + 
			TABLE_CATEGORY + "(" + COLUMN_CATEGORY_ID + " INTEGER PRIMARY KEY  AUTOINCREMENT NOT NULL,"  + 
			COLUMN_CATEGORY_NAME + " VARCHAR," + COLUMN_CATEGORY_AVAR +  "VARCHAR )";
	
	private static final String DROP_TABLE_INCOMES = "DROP TABLE IF EXISTS "
			+ TABLE_INCOMES;
	
	private static final String DROP_TABLE_EXPENSES = "DROP TABLE IF EXISTS "
			+ TABLE_EXPENSES;
	
	private static final String DROP_TABLE_PAYEE = "DROP TABLE IF EXISTS "
			+ TABLE_PAYEE;
	
	private static final String DROP_TABLE_PAYER = "DROP TABLE IF EXISTS "
			+ TABLE_PAYER;
	
	private static final String DROP_TABLE_ACCOUNT = "DROP TABLE IF EXISTS "
			+ TABLE_ACCOUNT;
	
	private static final String DROP_TABLE_CATEGORY = "DROP TABLE IF EXISTS "
			+ TABLE_CATEGORY;
	
	public static void onCreate(SQLiteDatabase db) {
		db.execSQL(ProcessSchema.COMMAND_CREATE_INCOMES);
		db.execSQL(ProcessSchema.COMMAND_CREATE_EXPENSES);
		db.execSQL(ProcessSchema.COMMAND_CREATE_PAYEE);
		db.execSQL(ProcessSchema.COMMAND_CREATE_PAYER);
		db.execSQL(ProcessSchema.COMMAND_CREATE_ACCOUNT);
		db.execSQL(ProcessSchema.COMMAND_CREATE_CATEGORY);
	}

	public static void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL(DROP_TABLE_INCOMES);
		db.execSQL(DROP_TABLE_EXPENSES);
		db.execSQL(DROP_TABLE_PAYEE);
		db.execSQL(DROP_TABLE_PAYER);
		db.execSQL(DROP_TABLE_ACCOUNT);
		db.execSQL(DROP_TABLE_CATEGORY);
		onCreate(db);
	}
}
